package org.hcyspartnoc.demo.controller.course;

import jakarta.validation.Valid;
import jakarta.validation.constraints.NotNull;
import org.hcyspartnoc.demo.common.core.AjaxResult;
import org.hcyspartnoc.demo.common.core.annotation.Log;
import org.hcyspartnoc.demo.common.core.annotation.PreAuthorize;
import org.hcyspartnoc.demo.common.core.enums.BusinessType;
import org.hcyspartnoc.demo.pojo.dto.course.CourseInfoDto;
import org.hcyspartnoc.demo.pojo.vo.course.CourseListVo;
import org.hcyspartnoc.demo.pojo.vo.course.CourseVo;
import org.hcyspartnoc.demo.service.course.ICourseService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/course")
public class CourseController {
    @Resource
    private ICourseService courseService;

    @Log(title = "课程·获取·课程·列表", businessType = BusinessType.OTHER, isSaveResponseData = false)
    @PreAuthorize(auth = "course:get:course:list", descr = "通过用户ID获取权限下的课程列表")
    @GetMapping("/get/list")
    public AjaxResult getCourseListByUserID() {
        List<CourseListVo> courseVoList = courseService.getCourseListByUserID();
        return AjaxResult.success(courseVoList);
    }
    @Log(title = "课程·获取·课程·基础信息", businessType = BusinessType.OTHER, isSaveResponseData = false)
    @PreAuthorize(auth = "course:get:course:info", descr = "通过课程ID获取课程基础信息")
    @GetMapping("/get/info")
    public AjaxResult getCourseInfoByID(@NotNull @RequestParam Integer courseId) {
        CourseVo courseVo = courseService.getCourseInfoByID(courseId);
        return AjaxResult.success(courseVo);
    }


    @Log(title = "课程·更新·课程·基础信息", businessType = BusinessType.UPDATE)
    @PreAuthorize(auth = "course:update:course:info", descr = "更新课程基础信息")
    @PutMapping("/update/info")
    public AjaxResult updateCourseInfoByID(@Valid @RequestBody CourseInfoDto courseInfoDto) {
        courseService.updateCourseInfoByID(courseInfoDto);
        return AjaxResult.success();
    }

}
